﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bitcoin.Diagnostics
{
    public class LogService
    {
        private static ILogService _current;

        public static ILogService Current
        {
            get
            {
                if (_current == null)
                {
                    InitializePlatformService();
                }
                return _current;
            }
        }

        public static ILog GetLog(Type type)
        {
            return Current.GetLog(type);
        }

        private static void InitializePlatformService()
        {
            var platformServices = new string[]
            {
                "Bitcoin.Diagnostics.NetLogService, Bitcoin.Net40",
                "Bitcoin.Diagnostics.DebugLogService, bitcoin"
            };
            foreach (var platformService in platformServices)
            {
                Type serviceType = Type.GetType(platformService, false);
                if (serviceType != null)
                {
                    _current = (ILogService) Activator.CreateInstance(serviceType);
                    break;
                }
            }
        }
    }
}
